﻿using IDAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class HotelDAL<T> : IHotelDAL<T> where T : class
    {
        public HotelDAL(HotelDbContext context)
        {
            Context = context;
        }

        public HotelDbContext Context { get; }

        public async Task<int> AddHotelAsync(T t)
        {
            Context.Set<T>().AddAsync(t);
            return await Context.SaveChangesAsync();
        }

        public async Task<int> AddHotelRangeAsync(List<T> list)
        {
            Context.Set<T>().AddRangeAsync(list);
            return await Context.SaveChangesAsync();
        }

        public async Task<int> DeleteHotelAsync(T t)
        {
            Context.Set<T>().Remove(t);
            return await Context.SaveChangesAsync();
        }

        public async Task<int> DeleteHotelRangeAsync(List<T> list)
        {
            Context.Set<T>().RemoveRange(list);
            return await Context.SaveChangesAsync();
        }

        public IQueryable<T> GetHotelALL()
        {
            return Context.Set<T>();
        }

        public async Task<int> UpdateHotelAsync(T t)
        {
            Context.Set<T>().Update(t);
            return await Context.SaveChangesAsync();
        }

        public async Task<int> UpdateHotelRangeAsync(List<T> list)
        {
            Context.Set<T>().UpdateRange(list);
            return await Context.SaveChangesAsync();
        }
    }
}
